<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Files extends Admin_Controller {
	
	function __construct()
	{
		parent::__construct(1, 2, 3, 4, 5, 6, 7);
	}
	
	public function index()
	{
		$this->load->helper('file_helper');
		$data = array(
			'content' => $this->load->view('admin/files_list', null, true),
			'addJS' => array(
				'/js/ajaxupload.js',
				'/link/js_vars'
			)
		);
		$this->getPage($data);
	}
	
	public function upload_file()
	{
		$mUploadDir = 'uploads/users/'.$this->user->id.'/';
		$uploadDir = rootDir().$mUploadDir;
		
		if (!is_dir($uploadDir))
			mkdir($uploadDir);
		
		$uploadFile = now().'_'.preg_replace('/[^\w._-]/', '_', $_FILES['file']['name']);
		
		if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadDir.$uploadFile))
		{?><a href="/<?=$mUploadDir.$uploadFile?>"><?=$uploadFile?></a><br/>
			<input type="text" value="<?=base_url().$mUploadDir.$uploadFile?>" class="uploadedFileInput" />
			<? if (strpos($_FILES['file']['type'], 'image/') === 0) echo br().img(base_url().$mUploadDir.$uploadFile);
		}
		else
		{?>Ошибка загрузки<?}
	}
	
}

?>